<?php
/**
 * @file $HeadURL: imagecollective.php $
 * @author $Author: DongJC (dongjianchang@haibao.com) $
 * @date $Date: 2015-3-30 6:02:55 $
 * @brief 
 */
namespace haibao\www\business\imagecollective;

use haibao\www\business\BusinessException;

use \haibao\www\data\imagecollective\ImageCollective as ImageCollectiveData;
use \haibao\www\model\filter\imagecollective\ImageCollective as ImageCollectiveFilter;
use \haibao\www\data\imagecollective\ImageCollectivePic as ImageCollectivePicData;

class ImageCollective extends \haibao\www\business\Base{
	
	public static function getImageCollectiveList($filterModel){
		//self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_LIST);
		$imageCollectiveDate = new ImageCollectiveData();
		return $imageCollectiveDate->getOne($filterModel);
	}	
	
	public static function updateImageCollective($model){
		self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_EDIT);
		if(!$model->Id){
			throw new BusinessException('id不能为空');
		}
		$imageCollectiveDate = new ImageCollectiveData();
		$imageCollectiveDate->updateCollectiveDate($model);
		self::saveOperateHistory(self::FUNC_CODE_IMAGECOLLECTIVE_EDIT, $model->toArray(false));
	}
	
	public static function addImageCollective($model){
		self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_ADD);
		$imageCollectiveDate = new ImageCollectiveData();
		$imageCollectiveDate->imageCollectiveDate($model);
		self::saveOperateHistory(self::FUNC_CODE_IMAGECOLLECTIVE_ADD, $model->toArray(false));
	}
	
	public static function getLists($query){
		$imageCollectiveDate = new ImageCollectiveData();
		return $imageCollectiveDate->getAll($query);
	}
	
	public static function delImageCollective($id){
		if(!$id){
			throw new BusinessException('图集id不能为空');
		}
		self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_DEL);
		$imageCollectiveDate = new ImageCollectiveData();
		$imageCollectiveDate->delImageCollectiveById($id);
		self::saveOperateHistory(self::FUNC_CODE_IMAGECOLLECTIVE_DEL, array($id));
	}
	
	public static function addImageRelation($model){
		self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_ADD);
		$imageCollectiveDate = new ImageCollectiveData();	
		$imageCollectiveDate->saveImageCollectivePic($model);
		self::saveOperateHistory(self::FUNC_CODE_IMAGECOLLECTIVE_ADD, $model->toArray(false));
	}
	
	public static function addImageCollectivePro($model){
		self::checkOperation(self::FUNC_CODE_IMAGECOLLECTIVE_ADD);
		$imageCollectiveDate = new ImageCollectiveData();
		$imageCollectiveDate->saveImageCollectivePro($model);
		self::saveOperateHistory(self::FUNC_CODE_IMAGECOLLECTIVE_ADD, $model->toArray(false));
	}
	
	public static function haveImageCollectivePro($id){
		if(!$id) return false;
		$imageCollectiveDate = new ImageCollectiveData();
		return $imageCollectiveDate->haveImageCollectivePro($id);
	}
	
	public static function getImage($query){
		$imageCollectiveDate = new ImageCollectiveData();
		return $imageCollectiveDate->getAll($query);
	}
	/**
	 * 获得图集信息通过图集id
	 */
	public static function getImageColletiveById($id){
		if(!$id){
			throw new BusinessException('图集id不能为空');
		}
		$imageCollectiveDate = new ImageCollectiveData();
		$imageCollectiveFilter = new ImageCollectiveFilter();
		$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_ID, \haibao\frame\data\query\Condition::CONDITION_EQUAL, $id);
		return $imageCollectiveDate->getOne($imageCollectiveFilter);
	}
	
	public static function getImageCollectiveByFilter($filter){
		$imageCollectiveDate = new ImageCollectiveData();
		return $imageCollectiveDate->getAll($filter);
	}

	public static function delImageCollectivePic($imageId,$id){
		if(!$imageId){
			throw new BusinessException('图片id不能为空');
		}
		if(!$id){
			throw new BusinessException('id不能为空');
		}
		$imageCollectiveData = new ImageCollectiveData();
		$imageCollectiveData->delImageCollectivePic($imageId,$id);
	}
	
	/**
	 * 得到图片描述
	 * @param unknown $query
	 */
	public static function getImageCollectivePicInfo($query){
		$imageCollectivePicData = new ImageCollectivePicData();
		return $imageCollectivePicData->getAll($query);
	}
	
	/**
	 * 保存图片描述（单张）
	 * @param  $model
	 */
	public static function updateImageCollectivePicInfo($model){
		if(!$model->ImageId){
			throw new BusinessException('图片id不能为空');
		}		
		$imageCollectivePicData = new ImageCollectivePicData();
		$imageCollectivePicData->save($model);
	}
	
	/**
	 * 批量更新图片描述
	 * @param string $imageIdStr
	 * @param string $desc
	 * @param int $imageCollectiveId
	 */
	public static function updateImageCollectivePicInfoBatch($imageIdStr,$desc,$imageCollectiveId){
		if(!$imageIdStr){
			throw new BusinessException('图片id不能为空');
		}
		if(!$desc){
			throw new BusinessException('描述不能为空');
		}
		if(!$imageCollectiveId){
			throw new BusinessException('图集id不能为空');
		}
		$imageCollectiveData = new ImageCollectiveData();
		$imageCollectiveData->updateBatch($imageIdStr,$desc,$imageCollectiveId);
	}

	public static function addProPicOne($imageId,$type,$imageCollectiveId){
		if(!$imageId){
			throw new BusinessException('图片id不能为空');
		}
		if(!$type){
			throw new BusinessException('图片类型不能为空');
		}
		if(!$imageCollectiveId){
			throw new BusinessException('图集id不能为空');
		}
		$imageCollectiveData = new ImageCollectiveData();
		$imageCollectiveData->updateImageCollectivePro($imageId,$type,$imageCollectiveId);
	}
	
	public static function delProPicOne($imageId,$type,$imageCollectiveId){
		if(!$imageId){
			throw new BusinessException('图片id不能为空');
		}
		if(!$type){
			throw new BusinessException('图片类型不能为空');
		}
		if(!$imageCollectiveId){
			throw new BusinessException('图集id不能为空');
		}
		$imageCollectiveData = new ImageCollectiveData();
		$imageCollectiveData->delImageCollectivePro($imageId,$type,$imageCollectiveId);
	}

}
